package io.github.luons.mediator.demo;

import io.github.luons.docs.DocsConfig;
import io.github.luons.mediator.generator.ApiGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

@ServletComponentScan(basePackages = "io.github.luons")
@SpringBootApplication(scanBasePackages = "io.github.luons")
public class ApiDemoApplication {

    public static void main(String[] args) {
        System.out.println("################# begin to genOpenApi");
        genOpenApi();
        System.out.println("################# end to genOpenApi");
        SpringApplication.run(ApiDemoApplication.class, args);
    }

    private static void genOpenApi() {
        List<String> controllers = Arrays.asList("DemoTest2Controller");
        ApiGenerator.initConfig("api-demo", "v2", "api-demo.XXX.com", "/demo-openapi/api-demo");
        ApiGenerator.ymlService(controllers, getDocsConfig("doc"));
        System.out.println("################# end to genOpenApi");
        // Docs.buildHtmlDocs(getDocsConfig("doc/apidoc/"));
    }

    private static DocsConfig getDocsConfig(String docPath) {
        DocsConfig config = new DocsConfig();
        config.setProjectPath(new File("").getAbsolutePath());
        config.setDocsPath(docPath);
        config.setApiVersion("");
        config.setProjectName("API demo Server");
        //config.setAutoGenerate(Boolean.TRUE);
        //config.setControllerFileNameList(Collections.singletonList("DemoTest2Controller"));

        // config.addPlugin(new MarkdownDocPlugin());
        return config;
    }

}
